import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入登录注册组件
import Reg from '@/views/Reg/Reg.vue'
import Login from '@/views/Login/Login.vue'
// 导入后台主页组件
import Main from '@/views/Main/Main.vue'
// 导入Home组件
import Home from '@/views/Menus/Home/Home.vue'
// 导入UserInfo组件
import UserInfo from '@/views/Menus/User/UserInfo.vue'
// 导入UserAvatar组件
import UserAvatar from '@/views/Menus/User/UserAvatar.vue'
// 导入UserPwd组件
import UserPwd from '@/views/Menus/User/UserPwd.vue'
// 导入文章分类组件
import ArtCate from '@/views/Menus/Article/ArtCate.vue'
// 导入Artlist组件
import ArtList from '@/views/Menus/Article/ArtList.vue'

Vue.use(VueRouter)

// 把下面的代码粘贴到路由模块中对应的位置，即可防止路由报错的问题
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
	return originalPush.call(this, location).catch(err => err)
}

// 声明路由规则
const routes = [{
		path: '/reg',
		component: Reg
	},
	{
		path: '/login',
		component: Login
	},
	{
		path: '/',
		component: Main,
		// 开启路由重定向
		redirect: '/home',
		children: [
			// home 作为子路由规则
			{
				path: 'home',
				component: Home
			},
			// 用户信息的子路由规则
			{
				path: 'user-info',
				component: UserInfo
			},
			// 更换头像的子路由规则
			{
				path: 'user-avatar',
				component: UserAvatar
			},
			// 重置密码的子路由规则
			{
				path: 'user-pwd',
				component: UserPwd
			},
			// 文章分类
			{
				path: 'art-cate',
				component: ArtCate
			},
			// 文章列表
			{
				path: 'art-list',
				component: ArtList
			}

		]
	}

]


const router = new VueRouter({
	routes
})

export default router
